//
//  AppDelegate.m
//  Quiz
//
//  Created by YaoJacob on 15/10/31.
//  Copyright © 2015年 Roger. All rights reserved.
//

#import "AppDelegate.h"
#import <BugHD/BugHD.h>
#import "BNRViewController.h"
#import "RandomItems.h"
#import "BNRHypnosisView.h"
#import "BNRHypnosisViewController.h"
#import "BNRReminderViewController.h"
#import "BNRItemsViewController.h"
#import "BNRDrawViewController.h"
#import "BNRItemStore.h"


//@interface AppDelegate () <UIScrollViewDelegate>
//@property(nonatomic, weak) BNRHypnosisView* mBNRHypnosisView;
//@end

@implementation AppDelegate

//练习5
- (void)moveTabBarController {
    
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    BNRHypnosisViewController *hvc = [[BNRHypnosisViewController alloc] init];
    //    self.window.rootViewController = hvc;
    
    //    NSBundle *appBundle = [NSBundle mainBundle];
    //    BNRReminderViewController *rvc = [[BNRReminderViewController alloc]initWithNibName:@"BNRReminderViewController" bundle:appBundle];
    BNRReminderViewController *rvc = [[BNRReminderViewController alloc]init]; //同名的好处，自动加载了。
    
    //8.2
    BNRItemsViewController *tableVC = [[BNRItemsViewController alloc]init];
    
    //Navigation[添加表格 9.0]
    UINavigationController * navController = [[UINavigationController alloc]initWithRootViewController:tableVC];
    
    //DrawLines  12.
    BNRDrawViewController * drawVC = [[BNRDrawViewController alloc]init];
    
    BNRViewController *bvr =[[BNRViewController alloc]init];
    UITabBarController *tabBarController =[[UITabBarController alloc]init];
    tabBarController.viewControllers = @[hvc, rvc,bvr,navController, drawVC];//tableVC];
    self.window.rootViewController = tabBarController;
}

//入口点
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //练习1
    //RandomItems *items =[[RandomItems alloc] init];
    //[items EnterPoint];
    
    //练习2
    //    BNRViewController* quizVC = [[BNRViewController alloc] init];
    //    self.window.rootViewController = quizVC;
    
    //练习3
    
    //CGRect firstFrame = CGRectMake(160, 240, 100, 150);
    //    CGRect firstFrame = self.window.bounds;
    //    BNRHypnosisView* firstView = [[BNRHypnosisView alloc] initWithFrame:firstFrame];
    //    //    firstView.backgroundColor = [UIColor redColor];
    //    [self.window addSubview:firstView];
    
    //    CGRect secondFrame = CGRectMake(20, 30, 50, 50);
    //    BNRHypnosisView* secondView = [[BNRHypnosisView alloc] initWithFrame:secondFrame];
    //    secondView.backgroundColor = [UIColor greenColor];
    //    //[self.window addSubview:secondView];
    //    [firstView addSubview:secondView];
    
    //练习4
    //        CGRect screenRect = self.window.bounds;
    //        CGRect bigRect = screenRect;
    //        bigRect.size.width *= 2.0;
    //        //bigRect.size.height *= 2.0;
    //
    //        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:screenRect];
    //        [scrollView setPagingEnabled:YES];
    //        [self.window addSubview:scrollView];
    //
    //        BNRHypnosisView *hyponsisView =[[BNRHypnosisView alloc]initWithFrame:screenRect];
    //        [scrollView addSubview:hyponsisView];
    //
    //        screenRect.origin.x += screenRect.size.width;
    //        BNRHypnosisView *hyponsisViewOther =[[BNRHypnosisView alloc]initWithFrame:screenRect];
    //        [scrollView addSubview:hyponsisViewOther];
    //        scrollView.contentSize = bigRect.size;
    //'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'
    
    //        self.mBNRHypnosisView = hyponsisView;
    //scrollView.delegate = self;
    
    
    //[BugHD handleCrashWithKey:@"cf7fe7318e3e5c6643dd72de07ebf83d"];   //Quiz_IOS.
    
    [self moveTabBarController];
    
    
    NSLog(@"%@", NSStringFromSelector(_cmd));
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    BOOL success = [[BNRItemStore sharedStore]saveChanges];
    if (success) {
        NSLog(@"save ok");
    }
    else
    {
        NSLog(@"save faild");
    }
    
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

//- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
//{
//    return self.mBNRHypnosisView;
//}

@end
